﻿using BLL;
using Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace UI
{
    public partial class AddMemberInfoForm : Form
    {
        private MeberTypeBLL _meberTypeBLL = new MeberTypeBLL();
        public AddMemberInfoForm()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;
        }

        private void AddMemberInfoForm_Load(object sender, EventArgs e)
        {
            //获取会员等级信息
            InitMemberInfo();
        }


        private void InitMemberInfo()
        {
            //调用BLL层查询会员信息
            cmbMemType.DisplayMember = "tname";
            cmbMemType.ValueMember = "tid";
            cmbMemType.DataSource = _meberTypeBLL.SelectMemberTpye();

        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            //接收会员信息
            MemberInfo memberInfo = new MemberInfo();

            memberInfo.Mname = txtMname.Text;
            memberInfo.Gender = rdoMan.Checked ? "男" : "女";
            //会员等级  
            memberInfo.Type = Convert.ToInt32(cmbMemType.SelectedValue);
            memberInfo.Discount = Convert.ToDouble(txtDisount.Text);
            memberInfo.Money = Convert.ToDouble(txtMoney.Text);
            memberInfo.Points = Convert.ToInt32(txtPoints.Text);
            memberInfo.Birthday = birDate.Value;
            memberInfo.RegistDate = registDate.Value;
            memberInfo.EndDate = endDate.Value;
            memberInfo.PhoneNum = txtPhoneNum.Text;

            //调用BLL
            if (_meberTypeBLL.AddMemberInfo(memberInfo) > 0)
            {
                MessageBox.Show("添加成功");

                this.DialogResult = DialogResult.OK;
            }
            else
            {
                MessageBox.Show("添加失败");
            }
            
        }
    }
}
